package com.xtravel.tweet.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.core.BitmapSize;
import com.xtravel.R;
import com.xtravel.tweet.database.dto.Wisher;


import java.util.List;

public class TweetDetailHorizontalListViewAdapter extends BaseAdapter {
    private Context mContext;  
    private LayoutInflater mInflater;
    private List<Wisher> wishers;
    private BitmapUtils bitmapUtils;
    Bitmap iconBitmap;

    private int selectIndex = -1;  
  
    public TweetDetailHorizontalListViewAdapter(Context context, List<Wisher> wishers){
        this.mContext = context;
        this.mInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//LayoutInflater.from(mContext);
        this.bitmapUtils = new BitmapUtils(context);
        this.wishers = wishers;
/*        this.wishers = new ArrayList<>();
        Wisher wisher = new Wisher();
        wisher.avatarUri = "http://tp3.sinaimg.cn/1903012754/50/5728871029/1";
        this.wishers.add(wisher);
        this.wishers.add(wisher);
        this.wishers.add(wisher);
        this.wishers.add(wisher);
        this.wishers.add(wisher);*/
    }
    @Override  
    public int getCount() {
        if(wishers == null){
            return 0;
        }
        return wishers.size();
    }  
    @Override  
    public Object getItem(int position) {  
        return position;  
    }  
  
    @Override  
    public long getItemId(int position) {  
        return position;  
    }  
  
    @Override  
    public View getView(int position, View convertView, ViewGroup parent) {
  
        ViewHolder holder;  
        if(convertView==null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.activity_tweet_detail_img, null);
            holder.mImage=(ImageView)convertView.findViewById(R.id.tweet_detail_img);
            convertView.setTag(holder);  
        }else{  
            holder=(ViewHolder)convertView.getTag();  
        }

/*        final Wisher wisher = wishers.get(position);
        setImageUrl(bitmapUtils,  holder.mImage,wisher.avatarUri, 0, 0);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, OtherIndexActivity.class);
                intent.putExtra("id",wisher.id);
                mContext.startActivity(intent);
            }
        });*/

        return convertView;  
    }  
  
    private static class ViewHolder {
        private ImageView mImage;  
    }

    public void setImageUrl(BitmapUtils bitmapUtils, ImageView imageView, String imageUrl, int width, int height) {
        BitmapDisplayConfig config = new BitmapDisplayConfig();
        config.setShowOriginal(false);
        config.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fade_in));

        if (width > 0 && height > 0) {
            DisplayMetrics dm = imageView.getResources().getDisplayMetrics();
            width *= dm.density;
            height *= dm.density;

            config.setBitmapMaxSize(new BitmapSize(width, height));
        }

        bitmapUtils.display(imageView, imageUrl, config);
    }
}